package com.yidu.ladder.base.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yidu.ladder.base.dao.TimeDao;
import com.yidu.ladder.base.domain.Time;
import com.yidu.ladder.base.domain.TimeVo;
import com.yidu.ladder.base.service.TimeService;

@Service
public class TimeServiceimpl  implements TimeService{
	@Autowired
	private TimeDao timeDao;
	

	public TimeServiceimpl(TimeDao timeDao) {
		super();
		this.timeDao = timeDao;
	}


	public TimeServiceimpl() {
		super();
	}


	public TimeDao getTimeDao() {
		return timeDao;
	}


	public void setTimeDao(TimeDao timeDao) {
		this.timeDao = timeDao;
	}
	@Override
	public Map<String, Object> pageQuerytime(TimeVo timeVo) {
		int page = (timeVo.getPage() - 1) * timeVo.getLimit();
		timeVo.setPage(page);
		List<Time> query = timeDao.pageQueryTime(timeVo);
		int count = timeDao.countUserByCriteria(timeVo);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("count", count);
		map.put("data", query);
		return map;
	}


	@Override
	public Boolean updatefreeze(String timeIdstr, String flag) {
		Map<String, Object> paraMap = new HashMap<String, Object>();
		String useable = flag;
		String[] timeIds = timeIdstr.split(",");
		int total = 0;
		for (int i = 0; i < timeIds.length; i++) {
			// 添加ID
			paraMap.put("timeId", timeIds[i]);
			paraMap.put("useable", useable);
			int result = timeDao.updatefreeze(paraMap);
			total += result;
		}
		return total == timeIds.length ? true : false;
	}


	@Override
	public int addtime(Time time) {
		return timeDao.addstandard(time);
	}


	@Override
	public int updatepicture(Time time) {
		int update=timeDao.update(time);
		int updateStaff=timeDao.updateStaff(time);
		if(update ==1 && updateStaff==1) {
			return 1;
		}else {
			return 0;
		}
	}





}
